package action.admin.feedback;

import beans.FeedBackBean;
import dao.FeedBackDAO;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "createFeedBack", urlPatterns = {"/createFeedBack"})
public class createFeedBack extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String acc_id = request.getParameter("acc_id");
            String question = request.getParameter("question");
            String class_id = request.getParameter("class_id");
            String msg = "";
            String error = "";
            if (question != null && !question.equals("")) {
                if (class_id != null && !class_id.equals("")) {
                    FeedBackBean fbBean = new FeedBackBean();
                    fbBean.setAcc_id(acc_id);
                    fbBean.setQuestion(question);
                    fbBean.setClass_id(class_id);
                    FeedBackDAO fb_DAO = new FeedBackDAO();
                    if (fb_DAO.createFeedBack(fbBean)) {
                        msg = "Create FeedBack successful";
                        request.setAttribute("msg", msg);
                        RequestDispatcher rd = request.getRequestDispatcher("student.jsp?page=listFB");
                        rd.forward(request, response);
                    } else {
                        error = "Create FeedBack Error !";
                        request.setAttribute("error", error);
                        RequestDispatcher rd = request.getRequestDispatcher("student.jsp?page=createFB");
                        rd.forward(request, response);
                    }
                } else {
                    error = "Create FeedBack Error - Insert Class !";
                    request.setAttribute("error", error);
                    RequestDispatcher rd = request.getRequestDispatcher("student.jsp?page=createFB");
                    rd.forward(request, response);

                }
            } else {
                error = "Create FeedBack Error - Insert Question !";
                request.setAttribute("error", error);
                RequestDispatcher rd = request.getRequestDispatcher("student.jsp?page=createFB");
                rd.forward(request, response);
            }
        } catch (Exception e) {
        }
    }
}
